/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tan_alumnoDAOImpl implements orm.dao.Tan_alumnoDAO {
	public Tan_alumno loadTan_alumnoByORMID(String al_id_alumno) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return loadTan_alumnoByORMID(session, al_id_alumno);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno getTan_alumnoByORMID(String al_id_alumno) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return getTan_alumnoByORMID(session, al_id_alumno);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno loadTan_alumnoByORMID(String al_id_alumno, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return loadTan_alumnoByORMID(session, al_id_alumno, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno getTan_alumnoByORMID(String al_id_alumno, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return getTan_alumnoByORMID(session, al_id_alumno, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno loadTan_alumnoByORMID(PersistentSession session, String al_id_alumno) throws PersistentException {
		try {
			return (Tan_alumno) session.load(orm.Tan_alumno.class, al_id_alumno);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno getTan_alumnoByORMID(PersistentSession session, String al_id_alumno) throws PersistentException {
		try {
			return (Tan_alumno) session.get(orm.Tan_alumno.class, al_id_alumno);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno loadTan_alumnoByORMID(PersistentSession session, String al_id_alumno, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tan_alumno) session.load(orm.Tan_alumno.class, al_id_alumno, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno getTan_alumnoByORMID(PersistentSession session, String al_id_alumno, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tan_alumno) session.get(orm.Tan_alumno.class, al_id_alumno, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno[] listTan_alumnoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return listTan_alumnoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno[] listTan_alumnoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return listTan_alumnoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno[] listTan_alumnoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tan_alumno as Tan_alumno");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tan_alumno[]) list.toArray(new Tan_alumno[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno[] listTan_alumnoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tan_alumno as Tan_alumno");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tan_alumno[]) list.toArray(new Tan_alumno[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno loadTan_alumnoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return loadTan_alumnoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno loadTan_alumnoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return loadTan_alumnoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno loadTan_alumnoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tan_alumno[] tan_alumnos = listTan_alumnoByQuery(session, condition, orderBy);
		if (tan_alumnos != null && tan_alumnos.length > 0)
			return tan_alumnos[0];
		else
			return null;
	}
	
	public Tan_alumno loadTan_alumnoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tan_alumno[] tan_alumnos = listTan_alumnoByQuery(session, condition, orderBy, lockMode);
		if (tan_alumnos != null && tan_alumnos.length > 0)
			return tan_alumnos[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTan_alumnoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return iterateTan_alumnoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTan_alumnoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return iterateTan_alumnoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTan_alumnoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tan_alumno as Tan_alumno");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTan_alumnoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tan_alumno as Tan_alumno");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno createTan_alumno() {
		return new orm.Tan_alumno();
	}
	
	public boolean save(orm.Tan_alumno tan_alumno) throws PersistentException {
		try {
			orm.AnotacionespowaPersistentManager.instance().saveObject(tan_alumno);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tan_alumno tan_alumno) throws PersistentException {
		try {
			orm.AnotacionespowaPersistentManager.instance().deleteObject(tan_alumno);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tan_alumno tan_alumno)throws PersistentException {
		try {
			if(tan_alumno.getCu_id_curso() != null) {
				tan_alumno.getCu_id_curso().tan_alumno.remove(tan_alumno);
			}
			
			orm.Tan_anotacion[] lTan_anotacions = tan_alumno.tan_anotacion.toArray();
			for(int i = 0; i < lTan_anotacions.length; i++) {
				lTan_anotacions[i].setAl_id_alumno(null);
			}
			return delete(tan_alumno);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tan_alumno tan_alumno, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(tan_alumno.getCu_id_curso() != null) {
				tan_alumno.getCu_id_curso().tan_alumno.remove(tan_alumno);
			}
			
			orm.Tan_anotacion[] lTan_anotacions = tan_alumno.tan_anotacion.toArray();
			for(int i = 0; i < lTan_anotacions.length; i++) {
				lTan_anotacions[i].setAl_id_alumno(null);
			}
			try {
				session.delete(tan_alumno);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tan_alumno tan_alumno) throws PersistentException {
		try {
			orm.AnotacionespowaPersistentManager.instance().getSession().refresh(tan_alumno);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tan_alumno tan_alumno) throws PersistentException {
		try {
			orm.AnotacionespowaPersistentManager.instance().getSession().evict(tan_alumno);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_alumno loadTan_alumnoByCriteria(Tan_alumnoCriteria tan_alumnoCriteria) {
		Tan_alumno[] tan_alumnos = listTan_alumnoByCriteria(tan_alumnoCriteria);
		if(tan_alumnos == null || tan_alumnos.length == 0) {
			return null;
		}
		return tan_alumnos[0];
	}
	
	public Tan_alumno[] listTan_alumnoByCriteria(Tan_alumnoCriteria tan_alumnoCriteria) {
		return tan_alumnoCriteria.listTan_alumno();
	}
}
